package cn.yan.luowowo.controller;

import cn.yan.luowowo.domain.StrategyCatalog;
import cn.yan.luowowo.query.StrategyCatalogQuery;
import cn.yan.luowowo.service.DestinationService;
import cn.yan.luowowo.service.StrategyCatalogService;
import cn.yan.luowowo.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("strategyCatalog")
public class StrategyCatalogController {

    @Autowired
    private StrategyCatalogService strategyCatalogService;

    @Autowired
    private DestinationService destinationService;


    @RequestMapping("/list")
    public String list(Model model, @ModelAttribute("qo")StrategyCatalogQuery qo){

        Page<StrategyCatalog> page = strategyCatalogService.query(qo);

        model.addAttribute("page",page);

        return "strategyCatalog/list";

    }


    @RequestMapping("/getDestByDeep")
    @ResponseBody
    public Object getDestByDeep(int deep) throws Exception{
        //查询
       return destinationService.list();

    }

    //修改or添加
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(StrategyCatalog strategyCatalog){
        strategyCatalogService.saveOrUpdate(strategyCatalog);
        return JsonResult.success();
    }

}
